package com.woniuxy.amusementparkos.util.lzw.result;

import com.woniuxy.amusementparkos.exception.lzw.unifyhanding.code.PublicCode;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

/**
 * @author lizhiwen
 * @create 2020-04-24 5:50 下午
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class ResponseResult<T> {
    private boolean success = true;
    private Integer code;
    private String msg;
    private T data;

    /**
     * 添加两个扩展的构造器
     *    更详尽的处理异常
     * @param publicCode
     */
    public ResponseResult(PublicCode publicCode){
        this.success = publicCode.isSuccess();
        this.code = publicCode.getCode();
        this.msg = publicCode.getMessage();
    }

    public ResponseResult(PublicCode publicCode,T data){
        this.success = publicCode.isSuccess();
        this.code = publicCode.getCode();
        this.msg = publicCode.getMessage();
        this.data = data;
    }

    /**
     * 方便其他使用者，依然按照原内容操作
     *
     * @param code
     * @param msg
     * @param data
     */
    public ResponseResult(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
}
